home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0294.ZIP
/
INTEREST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1985-05-18
|
2KB
|
101 lines
/*
amount = starting balance
balance = remaining balance
rate = interest rate per period
rate1 = interest rate per year
payment = monthly payment
principal = payment to principle
interest = payment of interest per period
*******************************************************/
/* declare variables */
float amount;
float balance =0;
float rate1;
float rate;
float payment;
float principal = 0;
float interest = 0;
/* ************************** */
#include "stdio.h"
FILE *outfile, *fopen(), *fclose();
interest1() /* call compute and print results */
{
static char out_name[]="amortize.txt";
outfile = fopen(out_name,"w");
if(outfile == NULL)
printf("cant open amortize.txt\n");
balance = amount;
int x =0;
printf(" payment interest principal balance\n");
fprintf(outfile," payment interest principal balance\n");
while (balance >0) /* call compute and print results */
{
compute();
printf("%8.2f %8.2f %8.2f %8.2f %d\n",payment, interest,
principal, balance, ++x);
fprintf(outfile,"%8.2f %8.2f %8.2f %8.2f %d\n",payment, interest,
principal, balance,x);
line();
if (x%12 ==0) /* pause every 12 payments */
{
printf("press return ");
getchar();
}
}
fclose(outfile);
printf("Done. The results have been saved in a file named %s\n",out_name);
}
/* compute balance */
compute()
{
if (balance > payment)
{
interest = balance * rate;
principal = payment - interest;
balance = balance - principal;
return (interest);
return (principal);
return (balance);
}
else
{
interest = balance * rate;
payment = balance + interest;
principal = payment - interest;
balance = balance - principal;
return (interest);
return (payment);
return (principal);
return (balance);
}
}
line()
{
int x = 0;
while (x++<=78)
{
printf("-");
fprintf(outfile,"-");
}
putchar('\n');
fprintf(outfile,"\n");
}